package com.bapoint.springsecurity.config;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import java.io.IOException;

/**
 * @ClassName LoginFailureHandler
 * @Description 登录失败处理器
 * @Author 王逸攀
 * @Date 2024/3/6 20:30
 * @Version 1.0
 */
public class LoginFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().write("登录失败");
        System.out.println("登录异常信息");
        exception.printStackTrace();
    }
}
